home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-1.iso / Files / Internet / Misc / Uupc 3.1 sources.sit / uupc 3.1 sources Folder / Mac specific / Unix lib / mkdir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-18  |  1.7 KB  |  103 lines  |  [TEXT/KAHL]

  1. #ifdef THINK_C
  2. # include "unixlibproto.h"
  3. #endif THINK_C
  4.  
  5. #ifndef  THINK_C
  6. #include <errno.h>
  7. #include <memory.h>
  8. #include <pb.h>
  9. #include <aztec/shell.h>
  10.  
  11. #define _DEBUG
  12. #include <max/debug.h>
  13. #ifdef TEST
  14. #include <stdio.h>
  15. #endif
  16.  
  17. #ifndef NULL
  18. #define NULL 0L
  19. #endif
  20.  
  21. #include "mkdir.proto.h"
  22.  
  23. mkdir(char *path)
  24. {
  25.  
  26.     char npath[255];
  27.     CInfoPBRec cpb;
  28.     int err;
  29.     register char * cp;
  30.  
  31.  
  32.     /* fix name, and get volume reference number */
  33.  
  34.  
  35.     cpb.ioVRefNum =  hfixnam( path, npath );
  36.  
  37. #ifdef TEST
  38.     fprintf( stderr, "opendir: %s\n", npath );
  39. #endif
  40.  
  41.     cpb.ioNamePtr = ctop( npath );
  42.     cpb.ioFDirIndex = 0;
  43.     cpb.u.di.ioDrDirID = 0L;
  44.     if ((err = PBDirCreate( &cpb, 0 )) != 0 ) {
  45.         printmsg( 0, "setdir: PBDirCreate error %d on %s\n", err, path );
  46.         return ENOENT;
  47.     }
  48.  
  49.  
  50.  
  51.     return 0;
  52.  
  53. }
  54.  
  55. #ifdef TEST
  56. main(void)
  57. {
  58.     char command[100];
  59.  
  60.     gets( command );
  61.     fprintf( stderr, "%d\n", mkdir( command ));
  62. }
  63.  
  64. #endif
  65. #else    THINK_C
  66. # include    <string.h>
  67. #ifndef NULL
  68. #define NULL 0L
  69. #endif
  70.  
  71. OSErr mkdir(char *path)
  72. {
  73.     HParamBlockRec    pb;
  74.     WDPBRec            wd;
  75.     char            npath[255];
  76.     int                idx, len;
  77.     
  78.     cnvMac(path, npath);        /* convert to Mac-style pathname */
  79.     if (strchr(npath, ':') == NULL || *npath == ':') {
  80.         /* relative to the current working directory */
  81. #ifdef THINK_C
  82.         memset((char *)(&wd), (int)NULL, (size_t)sizeof(wd));
  83. #else THINK_C
  84.         repmem((char *)&wd, "", 1, sizeof(wd));
  85. #endif THINK_C
  86.         /* get parent dir id */
  87.         if (PBHGetVol(&wd, false) != noErr) {
  88.             return -1;
  89.         }
  90.         pb.fileParam.ioDirID = wd.ioWDDirID;
  91.     }
  92.     else {
  93.         /* absolute pathname */
  94.         pb.fileParam.ioDirID = 0;
  95.     }
  96.     CtoPstr(npath);
  97.     pb.fileParam.ioNamePtr = (StringPtr)npath;
  98.     pb.fileParam.ioVRefNum = 0;
  99.     pb.fileParam.ioCompletion = NULL;
  100.     return(PBDirCreate(&pb, FALSE));
  101. }
  102. #endif    THINK_C
  103.